﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TestORM1.Model;

namespace TestORM1
{
    class Program
    {
        static void Main(string[] args)
        {
            //热启动
            //双方各插入一条数据
            Console.WriteLine("*************** 热启动 ****************");
            FreeSqlHelper.Insert(new Blog("第一次添加", 0));
            SqlSugarHelper.Insert(new Blog("第一次添加", 0));
            // Console.WriteLine("测试完成");
            // Console.ReadLine();

            
            if (false)
            {
                // 先创建表，顺便填充1 000 000条炮灰数据
                for (int i = 0; i < 100; i++)
                {
                    List<Blog> itemList=new List<Blog>();
                    for (int j = 0; j < 10000; j++)
                    {
                        itemList.Add(new Blog("测试数据1" + j, i));
                    }
                    FreeSqlHelper.Insert(itemList);
                }
                Console.WriteLine("炮灰数据填装完毕");
                Console.ReadLine();
            }
            if (true)
            {
                //插入一条数据 循环1000次
                Console.WriteLine("*************** 插入一条数据 循环1000次 ****************");
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    for (int i = 0; i < 1000; i++)
                    {
                        FreeSqlHelper.Insert(new Blog("测试数据1", i));
                    }
                    sw.Stop();
                    Console.WriteLine("Freesql：" + sw.Elapsed.TotalMilliseconds + "ms");
                }
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    for (int i = 0; i < 1000; i++)
                    {
                        SqlSugarHelper.Insert(new Blog("测试数据1", i));
                    }
                    sw.Stop();
                    Console.WriteLine("SqlSugar：" + sw.Elapsed.TotalMilliseconds + "ms");
                }

                //插入10条数据 循环100次
                Console.WriteLine("*************** 插入10条数据 循环100次 ****************");
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    for (int i = 0; i < 100; i++)
                    {
                        List<Blog> itemList = new List<Blog>();
                        for (int j = 0; j < 10; j++)
                        {
                            itemList.Add(new Blog("测试数据1" + j, i));
                        }
                        FreeSqlHelper.Insert(itemList);
                    }
                    sw.Stop();
                    Console.WriteLine("Freesql：" + sw.Elapsed.TotalMilliseconds + "ms");
                }
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    for (int i = 0; i < 100; i++)
                    {
                        List<Blog> itemList = new List<Blog>();
                        for (int j = 0; j < 10; j++)
                        {
                            itemList.Add(new Blog("测试数据1" + j, i));
                        }
                        SqlSugarHelper.Insert(itemList);
                    }
                    sw.Stop();
                    Console.WriteLine("SqlSugar：" + sw.Elapsed.TotalMilliseconds + "ms");
                }
                //批量添加1000条数据 循环1次
                Console.WriteLine("*************** 批量添加1000条数据 循环1次 ****************");
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    List<Blog> itemList = new List<Blog>();
                    for (int j = 0; j < 1000; j++)
                    {
                        itemList.Add(new Blog("测试数据1" + j, j));
                    }
                    FreeSqlHelper.Insert(itemList);
                    sw.Stop();
                    Console.WriteLine("Freesql：" + sw.Elapsed.TotalMilliseconds + "ms");
                }
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    List<Blog> itemList = new List<Blog>();
                    for (int j = 0; j < 1000; j++)
                    {
                        itemList.Add(new Blog("测试数据1" + j, j));
                    }
                    SqlSugarHelper.Insert(itemList);
                    sw.Stop();
                    Console.WriteLine("SqlSugar：" + sw.Elapsed.TotalMilliseconds + "ms");
                }

                //根据ID获取 1000次
                Console.WriteLine("*************** 根据ID获取 1000次 ****************");
                List<int> idList=new List<int>();
                Random rd = new Random();
                for (int i = 0; i < 100; i++)
                {
                    idList.Add(rd.Next());
                }
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    foreach (var item in idList)
                    {
                        FreeSqlHelper.Get(item);
                    }
                    sw.Stop();
                    Console.WriteLine("Freesql：" + sw.Elapsed.TotalMilliseconds + "ms");
                }
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    foreach (var item in idList)
                    {
                        SqlSugarHelper.Get(item);
                    }
                    sw.Stop();
                    Console.WriteLine("SqlSugar：" + sw.Elapsed.TotalMilliseconds + "ms");
                }
                //根据ID排序分页（有索引）
                Console.WriteLine("*************** 根据ID排序分页（有索引） ****************");
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    FreeSqlHelper.GetListOrberId(853456);
                    sw.Stop();
                    Console.WriteLine("Freesql：" + sw.Elapsed.TotalMilliseconds + "ms");
                }
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    SqlSugarHelper.GetListOrberId(833456);
                    sw.Stop();
                    Console.WriteLine("SqlSugar：" + sw.Elapsed.TotalMilliseconds + "ms");
                }
                //根据时间排序分页（无索引）
                Console.WriteLine("*************** 根据时间排序分页（无索引） ****************");
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    FreeSqlHelper.GetListOrberTime(853556);
                    sw.Stop();
                    Console.WriteLine("Freesql：" + sw.Elapsed.TotalMilliseconds + "ms");
                }
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    SqlSugarHelper.GetListOrberTime(833656);
                    sw.Stop();
                    Console.WriteLine("SqlSugar：" + sw.Elapsed.TotalMilliseconds + "ms");
                }
                Console.ReadLine();
            }
            
        }
    }
}
